﻿
/*-------Records Search option for side Panel-------*/ // Added by 'Imran Gani' on 09-May-2013
function LoadSearch() {
    try {
        //setMB_property("EnableSearch", "SidePanel", "false"); // To reset the cookies value.
        var ShowSearch = getMB_property("EnableSearch", "SidePanel");
        if (ShowSearch == "true")
            addSearchControls();
        else {
            $.ajax({
                url: "mb_ajaxhandler.aspx?action=enable_search",
                dataType: "text",
                cache: false,
                success: function (msg) {
                    if (msg == "true")
                        addSearchControls();
                    setMB_property("EnableSearch", "SidePanel", msg);
                }
            });
        }
    }
    catch (Ex) { }
}
function addSearchControls() {
    try {
        $('#td_search').html("<div id=\"div_search\" class=\"search\">&nbsp; <input id=\"mb_txt_Srch\" class=\"controlFont\" type=\"text\" onkeydown=\"javascript:return mb_interceptRecordSearch(event);\" onfocus=\"javascript:mb_txtsrch_onfocus();\" value=\"Search records...\" title=\"Search records\" style=\"width:147px;position:relative;Color:#808080;padding-left:3px;vertical-align:middle;border:solid 1px #7F9DB9;height:20px;border-right:none;\" onblur=\"javascript:mb_txtsrch_onblur();\" tabindex=\"0\"></input><img id=\"mb_img_txtSrch\" class=\"SearchIcon\" style=\"border-width:0px;vertical-align:middle;\" onclick=\"javascript:return mb_doRecordSearch();\" title=\"Search records\" src=\"Images/objectSearch2_disabled.gif\" ></img></div>");
    }
    catch (Ex) { }
}
function mb_doRecordSearch() {
    try {
        if (document.getElementById("mb_txt_Srch") != null) {
            var strRecordSearch = document.getElementById("mb_txt_Srch").value;
            if (strRecordSearch.length < 1 || strRecordSearch == "Search records...") {
                alert("Please enter a search string to continue.");
                return false;
            }
            else {
                var mb_go_url = window.location.href.substr(0, window.location.href.lastIndexOf('/') + 1);
                document.location.href = mb_go_url + "Search.aspx?val=" + strRecordSearch;
                return false;
            }
        }
    }
    catch (ExSearch) { }
    return false;
}

function mb_interceptRecordSearch(event) {
    try {
        var code = (event.keyCode ? event.keyCode : event.which);
        if (code == 13) {
            return mb_doRecordSearch();
        }
    }
    catch (ExSearch) { }
}

function mb_txtsrch_onfocus() {
    try {
        if (document.getElementById('mb_txt_Srch').value == "Search records...") {
            document.getElementById('mb_txt_Srch').value = "";
            document.getElementById('mb_txt_Srch').style.color = document.getElementById('mb_txt_Srch').value == 'Search records...' ? '#808080' : '#000000';
        }
        document.getElementById('mb_img_txtSrch').src = "Images/objectSearch2.gif";
    }
    catch (Exc_srch) { }
}
function mb_txtsrch_onblur() {
    try {
        if (document.getElementById('mb_txt_Srch').value == "") {
            document.getElementById('mb_txt_Srch').value = "Search records...";
            document.getElementById('mb_txt_Srch').style.color = document.getElementById('mb_txt_Srch').value == 'Search records...' ? '#808080' : '#000000';
            document.getElementById('mb_img_txtSrch').src = "Images/objectSearch2_disabled.gif";
        }
    }
    catch (Exc_srch) { }
}
/*-------End of Records Search option for side Panel-------*/